<?php
	$user = $controller->getCurrentUser();    
	//on verifie les permissions
	if ($user->isAllowedTo(GRADE_MOD_BOOK))
	{
		$book = new book();
		if (!$request->getParam('idEdition') || !$request->getParam('idBook') || !$request->getParam('idAlbum'))
		{
			$controller->addError('Une erreur est survenue lors de l\'envoi des param&egrave;tres au serveur');
			$controller->forward('changeBook');	
		}
		else
		{
			$edition = edition::singleton($request->getParam('idEdition'));
			$album = album::singleton($request->getParam('idAlbum'));
			$book->setAlbumObject($album);
			$book->setEditionObject($edition);
			$book->setIdEdition($edition->getId());
			$book->getEditionObject()->setIdalbum($album->getId());
			
			//on renseigne l'objet book
			if ($condition = $request->getParam('bookCondition'))                                                       
				$book->setCondition($condition);
			else
				$book->delCondition();
				
			if (($publisherId = $request->getParam('publisherId')) && isset($publisherId) && is_numeric($publisherId))  
				$book->setIdpublisher($publisherId);
			else
				$book->detIdpublisher();
			
			if (($serie = $request->getParam('serie')) && isset($serie) && is_numeric($serie) )                         
				$book->setIdserie($serie);
			else
				$book->delIdserie();
			
			if ($description = $request->getParam('bookDescription'))                                                   
				$book->setDescription($description);
			else
				$book->delDescription();
			
			if (($price = $request->getParam('bookPrice')) && isset($price) && is_numeric($price))                      
				$book->setPrice($price);
			else
				$book->delPrice();
			
			if ($year = $request->getParam('bookYear'))                                                                 
				$book->setYear($year);
			else
				$book->delYear();
			
			if ($EAN13 = $request->getParam('bookEan13'))                                                               
				$book->setEan13($EAN13);
			else
				$book->delEan13();
			
			if ($emplacement = $request->getParam('bookEmplacement'))                                                   
				$book->setLocation($emplacement);
			else
				$book->delLocation();
			
			if ($cotation = $request->getParam('bookCotation'))                                                         
				$book->setCotation($cotation);
			else
				$book->delCotation();
			
			if ($parutionDate = $request->getParam('bookParutionDate'))                                                 
				$book->setParution($parutionDate);
			else
				$book->delParution();
			
			if (($tome = $request->getParam('bookTome')) && isset($tome) && is_numeric($tome))                          
				$book->setTome($tome);
			else
				$book->delTome();
			
			if ($name = $request->getParam('bookName'))                                                                 
				$book->setName($name);
			else
				$book->delName();
			
			if ($drawerList = $request->getParam('drawerList'))                                                         
				$book->setDrawerList($drawerList);
			else
				$book->delDrawerList();
			
			if ($scriptWritterList = $request->getParam('scriptWritterList'))                                           
				$book->setScriptWritterList($scriptWritterList);
			else
				$book->delScriptWritterList();
			
			if ($idBook = $request->getParam('idBook'))                                                                 
				$book->setId($idBook);
			else
				$book->delId();
			
			
			//si tout est OK, on ajoute
			if ($book->isReadyToAdd())
			{
				$request->clean('post');
				$book->update();
				$logPermAction = 'BD miste &agrave; jour : '.addslashes($book->getName());
				logPermactions($user->getId(), $logPermAction);
				$controller->addInformation('L\'album a bien &eacute;t&eacute; mis &agrave; jour !');
				$controller->forward('changeBook');
			}
			else //sinon on balance une erreur
			{
				$controller->addError('Veuillez remplir les champs necessaires !');  
				$controller->setVar('cotation', $book->getCotation());  
				unset($book);
				$controller->forward('changeBookStep3');
			}
		}
	}
	else
		$controller->render('errorRights');
  
?>
